package GameElement;

import java.util.LinkedList;

public class GameBoard {
	private int oneSideLength;				// Define the game board one size length
	
	/**
	 * Constructor to initialize game board one size length
	 * @param length
	 */
	public GameBoard(int length) {
		oneSideLength = length;
	}
	
	/**
	 * Store the game board as the string 2d array
	 * @return 2d array of game board
	 */
	public String [][] stringBoard() {
		String [][] arrayBoard = new String[oneSideLength][oneSideLength];
		for (int i = 10; i >= 0; i--) {
			arrayBoard[i][0] = new String((20-i)+"");
			if (i == 0) { 
				for (int j = 0; j < oneSideLength; j++) {
					arrayBoard[i][j] = new String((20+j)+"");
				}
			}
			arrayBoard[i][10] = new String((30+i)+""); 
			if (i == 10) {
				for (int k = 1; k < oneSideLength; k++) {
					arrayBoard[i][k] = new String("0"+(10-k)+"");
				}
			}
		}
		return arrayBoard;
	}
	
	/**
	 * Print the 2d array of game board and players information in console
	 * @param players
	 */
	public void printBoardConsole(GamePlayer[] players) {
		String [][] arrayBoard = stringBoard();
		splitLine(32);
		for (int i = 0; i < oneSideLength; i++) {
			for (int j = 0; j < oneSideLength; j++) {
				if (arrayBoard[i][j] != null)  
					System.out.print(arrayBoard[i][j] + " ");
				else
					System.out.print("  " + " ");
			}
			System.out.print("\n");
		}
		splitLine(50);
		System.out.print("Roles\t\tName\t\tPosition\tScore\n");
		for (int i=0; i<players.length; i++) {
			System.out.print(players[i].getRoles() + "\t\t" + players[i].getGamePlayerName() + "\t\t" + players[i].getPosition()+ "\t\t" + players[i].getScore() + "\n");
		}
		splitLine(50);
	}
	
	/**
	 * Print the split line to make clear the console display
	 * @param players
	 */
	private void splitLine(int numberOfspliter) {
		for (int i=0; i<numberOfspliter; i++) {
			System.out.print("=");
		}
		System.out.print("\n");
	}
}